home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 5.7 KB | 155 lines | [TEXT/MPS ] |
- {
- File: WriteLineWindow.p
-
- Contains: Routines to create and handle a scrollable transcript-type window.
- The expected use of this unit is for a 'debugging' window in an
- application.
-
- This unit hooks into the MPW 3.2 i/o hooks, so that once the debugging
- window is created, all output from Pascal writeln and C printf statements
- will be placed into this window.
-
- How to use:
- At the start of your application, call WWInit() and WWNew() or WWNewDefault.
- This will create and show the debugging window. In the main event loop,
- call WWEvent() after you get an event but before you handle it. If this
- function returns true, then it was an event associated with the debugging
- window and should be 'ignored' by your application.
-
- If you want all information sent to the window also written to a file,
- call WWRedirect() or WWFSpRedirect.
-
- To temporarily suspend output from you application, call the WWForce()
- function. This saves the current options on a stack and uses the new
- ones. When you are ready to restore the old options, call WWEndForce().
-
- You can call WWAddText() to add text to the window directly.
-
- Caveats: Since the window routines use global data, you can't have more than
- one transcript window in an application. These routines also can't be
- used in stand-alone code resources (although I do have a similar unit that
- can be used from stand-alone code - KSS)
-
- Written by: Bruce Horn, Steve Capps, Larry Kenyon,
- John Meier, scott douglass, Darin Adler,
- Paul Mercer, Bryan Stearns, Dave Owens
-
- Stolen from the Finder by: Keith Stattenfield
-
- Copyright: © 1990, 1991 by Apple Computer, Inc., all rights reserved.
-
- Change History:
-
- 11/25/91 KSS Add WWFLUSHOUTPUTFILE defn.
-
- 7/25/91 KSS Added WWNewDefault, WWFSpRedirect, some primitives to insert
- and a few 'standard' data types into the window. Wrote the
- Contains: and How to use: sections of this header.
-
- <5> 10/16/90 sad fix WWRedirect
- <4> 8/3/90 pm use NewHandleSys instead of NewHandle to make the memory
- difference between debug & SCM builds smaller
- <2+> 3/21/90 prp Debug window's line array memory is allocated by NewHandleClear
- instead NewHandle.
-
- To Do:
- }
-
- UNIT WriteLineWindow;
- {lifted from MacApp's WriteLnWindow}
- {Copyright 1985, 1986 Apple Computer, Inc}
-
- INTERFACE
-
- {$R-} {$D+}
-
- USES
- MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, PasLibIntf, Files, Folders, SysEqu;
-
- CONST
- kWWEol = CHR($0D);
- kForceDepth = 10;
-
- TYPE
- WrForceOptions = (forceOn, forceOff, forceUnchanged);
-
- VAR
- {$Z+}
- gDebugWindowPtr: WindowPtr;
- {$Z-}
- gWrToWindow: BOOLEAN; {set to TRUE to enable writelns to window}
- gWrToFile: BOOLEAN; {set to TRUE to enable writelns to file}
- {both are initialized to TRUE in WWInit}
-
- {All public procedure begin with WW (for WritelnWindow)}
- PROCEDURE WWInit(numLines, numCharsPerLine: INTEGER);
- {Call this once at the start of your program.}
-
- PROCEDURE WWNew(bounds: Rect; windowTitle: Str255; goAway: BOOLEAN; visible: BOOLEAN;
- outputFont, outputSize: INTEGER);
- {Call this to create a WriteLn window with given title.
- goAway is TRUE iff you want a go away box (IF the user clicks the go away box,
- the window will be hidden but not freed);
- visible is TRUE iff you want the window to be visible initially;
- outputFont & output size define the font to use
- }
-
- PROCEDURE WWNewDefault;
- PROCEDURE WWShowWindow;
-
- PROCEDURE WWForceOutput(wrToWindow, wrToFile: WrForceOptions);
- PROCEDURE WWEndForce;
- {Since it is now possible that one part of the program disables writelns to the window, you
- might want to guarantee that certain writelns appear in the window. WWForceOutput saves
- the values of gWrToWindow & gWrToFile on a stack (depth = kForceDepth), and sets
- these values according to the parameters. WWEndForce simply pops the stack.}
-
- FUNCTION WWRedirect(vRefNum: INTEGER; fileName: Str255): OSErr;
- {IF you call this, THEN subsequent writelns will be sent to the indicated file. (Assuming
- writing to the file is enabled. Pass '' for the fileName to close any open file.
- To append output to an existing file, place the characters '>>' at the start of the filename. }
-
- { This uses the FSSpec record introduced with MPW 3.2. A special case is that, if the vRefNum and
- the parID of the redirectFile are 0, then the file will be created in the current System Folder. }
- FUNCTION WWFSpRedirect (redirectFile : FSSpec; appendToExistingFile : boolean) : OSErr;
-
- FUNCTION WWReadCh: CHAR;
- FUNCTION WWReadLn(buffer: Ptr; byteCount: INTEGER): LONGINT;
- PROCEDURE WWAddText(textBuf: Ptr; byteCount: longint);
-
- {Call before SizeWindow if you need to resize the debug window programmatically}
- PROCEDURE WWInvalGrowBox;
- {Call after SizeWindow if you need to resize the debug window programmatically}
- PROCEDURE WWGrown;
-
- {Call the following procedures in response to events for the WriteLnWindow.
- (Test the window receiving the event against gDebugWindowPtr.}
- PROCEDURE WWActivateEvent(modifiers: INTEGER);
- PROCEDURE WWMouseDown(where: INTEGER; pt: Point; modifiers: INTEGER);
- PROCEDURE WWUpdateEvent;
- PROCEDURE WWScroll(howManyLines: INTEGER); {for UTrace use; negative arg scrolls backwards}
-
- PROCEDURE IDUWritelnWindow; {Writeln UWritelnWindow's compile time.}
-
- FUNCTION WWFirstLGlob: LongInt;
- FUNCTION WWLastLGlob: LongInt;
- FUNCTION WWFirstGlob: LongInt;
- FUNCTION WWLastGlob: LongInt;
-
- Function WWEvent(event: EventRecord): Boolean;
-
- { Keith's added convenience routines }
- PROCEDURE WWAddDate;
- PROCEDURE WWAddTime;
- PROCEDURE WWAddDateTime;
- PROCEDURE WWAddEncodedText (dataPtr : UNIV Ptr; dataSize : integer);
- PROCEDURE WWAddHexData (dataPtr : UNIV Ptr; dataSize : integer);
-
- PROCEDURE WWFlushOutputFile;
-
- IMPLEMENTATION
-
- {$I WriteLineWindow.inc1.p }
-
- END.
-